package com.ruibang.glass.quality.controller.manage;

import com.ruibang.glass.quality.domain.req.LabelReq;
import com.ruibang.glass.quality.domain.req.LabelSerialNumReq;
import com.ruibang.glass.quality.service.LabelService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @Author: songJinKang
 * @CreateTime: 2023-12-08  14:45
 * @Description: TODO:质量标签控制器
 * @Version: 1.0
 */

@RestController
@RequestMapping("/api/quality/manage/label")
@Api(value = "标签控制器", tags = {"标签控制器"})
public class LabelController {

    @Autowired
    private LabelService labelService;

    @PostMapping("/queryLabel")
    @ApiOperation(value = "查询标签信息", notes = "查询标签信息")
    public ResultBody queryLabel(@RequestBody LabelReq labelReq) {
        return ResultBody.success(labelService.queryLabel(labelReq));
    }

    @PostMapping("/getCode")
    @ApiOperation(value = "生成标签二维码", notes = "生成标签二维码")
    public ResultBody getCode(@RequestBody @Valid LabelReq labelReq) {
        return labelService.getCode(labelReq);
    }

    @PostMapping("/getDateByPalletNumber/{palletNumber}")
    @ApiOperation(value = "根据托盘号获取生产日期", notes = "根据托盘号获取生产日期")
    public ResultBody getDateByPalletNumber(@PathVariable String palletNumber) {
        return labelService.getDateByPalletNumber(palletNumber);
    }

    @GetMapping("/getSerialNumByGrade/{grade}")
    @ApiOperation(value = "根据玻璃种类获取流水号", notes = "根据玻璃种类获取流水号")
    public ResultBody getSerialNumByGrade(@PathVariable String grade) {
        return labelService.getSerialNumByGrade(grade);
    }

    @PostMapping("/editSerialNumBer")
    @ApiOperation(value = "修改流水号", notes = "修改流水号")
    public ResultBody editSerialNumBer(@RequestBody LabelSerialNumReq labelSerialNumReq) {
        return labelService.editSerialNumBer(labelSerialNumReq);
    }

    @GetMapping("/likePalletNumber")
    @ApiOperation(value = "匹配流水号", notes = "匹配流水号")
    public ResultBody likePalletNumber(@RequestParam String highlight) {
        return labelService.likePalletNumber(highlight);
    }

    @DeleteMapping("/deleteById/{labelId}")
    @ApiOperation(value = "根据id删除", notes = "根据id删除")
    public ResultBody deleteById(@PathVariable String labelId) {
        labelService.removeById(labelId);
        return ResultBody.success();
    }

    @PostMapping("/export")
    @ApiOperation(value = "数据导出", notes = "数据导出")
    public void export(@RequestBody LabelReq labelReq, HttpServletResponse httpResponse) {
        labelService.export(labelReq, httpResponse);
    }
}
